package com.kgc.scd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kgc.scd.bean.IndexPic;
import com.kgc.scd.mapper.IndexPicMapper;
import com.kgc.scd.service.IndexPicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: com.kgc.scd.service.impl
 * @author: HarryXzy
 * @create: 2022-06-16 12:26
 * @description:
 **/
@Service
public class IndexPicServiceImpl implements IndexPicService {
    @Autowired(required = false)
    private IndexPicMapper indexPicMapper;

    @Override
    public List<IndexPic> getAllIndexPic() {
        QueryWrapper<IndexPic> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("sort_id");
        wrapper.eq("logic_del",0);
        List<IndexPic> indexPics = indexPicMapper.selectList(wrapper);
        return indexPics;
    }

    @Override
    public void addPic(IndexPic indexPic) {
        indexPicMapper.insert(indexPic);
    }

    @Override
    public IndexPic getPicById(String indexPicId) {
       return indexPicMapper.selectById(indexPicId);
    }

    @Override
    public void deletePicById(String indexPicId) {
        IndexPic indexPic = new IndexPic();
        indexPic.setIndexpicId(indexPicId);
        indexPic.setLogic_del(1);
        indexPicMapper.updateById(indexPic);
    }

    @Override
    public boolean checkPic(IndexPic indexPic) {
        QueryWrapper<IndexPic> wrapper = new QueryWrapper<>();
        wrapper.eq("pic",indexPic.getPic());
        wrapper.eq("url",indexPic.getUrl());
        wrapper.eq("sort_id",indexPic.getSortId());
        return indexPicMapper.selectOne(wrapper) != null;
    }

    @Override
    public boolean changeSort(String indexPicId, Integer sort) {
        IndexPic indexPic = new IndexPic();
        indexPic.setIndexpicId(indexPicId);
        indexPic.setSortId(sort);
        return indexPicMapper.updateById(indexPic) > 0;
    }

    // 检查轮播图是否超过10
    @Override
    public boolean checkNum() {
        return false;
    }


}
